// 引入axios
import axios from 'axios'
// 请求延时（毫秒数，如果请求话费超过了'timeout'的时间，请求将被中断）
axios.defaults.timeout = 100000

const api_name = 'http://localhost:8333/home/homeFamily'

// 添加一个请求拦截器
axios.interceptors.request.use(function (config) {
    // 在请求发送之前，将 token 放入请求头中
    const token = localStorage.getItem('authorization');
    if (token) {
      config.headers.Authorization = `${token}`;
    }
    return config;
  }, function (error) {
    return Promise.reject(error);
  });


export default {
    //获得全部family
    getAllFamily() {
        return axios.get(`${api_name}/` + "getAllFamily")
    },

    addFamily(saveObj) {
        return axios.post(`${api_name}/` + "save", {
            familyName: saveObj.familyName,
        })
    },

    updateFamily(editFamily) {
        return axios.put(`${api_name}/` + "update",{
            id: editFamily.id,
            familyName: editFamily.familyName,
        })
    },

    remove(id) {
        return axios.delete(`${api_name}/` + "remove" + `/${id}`)
    },

    getFamilyById(id) {
        return axios.get(`${api_name}/` + "get" + `/${id}`)
    },

    pageList(page, limit, searchObj) {
        return axios.post(`${api_name}/${page}/${limit}`,{
            id : searchObj.id,
            familyName : searchObj.familyName,
        })
    },
}